package org.cbg.until;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.Border;

import com.tool.tcpimg.UIUtils;
import org.cbg.entity.Roleorder;
import org.cbg.panel.TraslationMyMainMygoodsModelJpanel;
import org.come.until.cbgSrcollPanelUI;

public class TraslationTableMygoodsUntil extends JPanel {

    public TraslationTableMygoodsUntil() {
        // TODO Auto-generated constructor stub

    }

    /**
     * 我的收藏阁我的货物
     * 
     * @param jScrollPane
     * @param geshu
     *            多少条数据
     */
    public static void TableModel(JScrollPane jScrollPane, int geshu) {

        /**
         * 设置监听
         */
        class MListener implements MouseListener {

            @Override
            public void mouseReleased(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mousePressed(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mouseExited(MouseEvent e) {
                // TODO Auto-generated method stub
                JPanel source = (JPanel) e.getSource();
                source.setBackground(null);
                source.setOpaque(false);
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                // TODO Auto-generated method stub
                JPanel source = (JPanel) e.getSource();
                source.setBackground(UIUtils.COLOR_cbg5);
                source.setOpaque(true);
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
            }
        }

        /**
         * 表格
         */
        JPanel jPanel = new JPanel();
        jPanel.setBackground(null);
        jPanel.setOpaque(false);
        jPanel.setBorder(null);
        jPanel.setLayout(null);
        jScrollPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(jScrollPane));
        jScrollPane.setViewportView(jPanel);
        jScrollPane.setOpaque(false);
        jScrollPane.setBorder(null);
        jScrollPane.getViewport().setOpaque(false);
        Border js = BorderFactory.createEmptyBorder();
        jScrollPane.setBorder(js);
        jScrollPane.setVerticalScrollBarPolicy(20);
        jScrollPane.setHorizontalScrollBarPolicy(31);
        for (int i = 0; i < geshu; i++) {
            TraslationMyMainMygoodsModelJpanel traslationMyMainMygoodsModelJpanel = new TraslationMyMainMygoodsModelJpanel();
            traslationMyMainMygoodsModelJpanel.setBounds(0, i * 62, 740, 60);
            MListener mListener = new MListener();
            traslationMyMainMygoodsModelJpanel.addMouseListener(mListener);
            jPanel.add(traslationMyMainMygoodsModelJpanel);
        }

        jPanel.setPreferredSize(new Dimension(760, 62 * geshu));
        jScrollPane.updateUI();
        jScrollPane.invalidate();
        jScrollPane.validate();
        jScrollPane.repaint();
    }

    /**
     * 我的收藏阁我的货物 根据数据库数据添加信息
     * 
     * @param jScrollPane
     * @param geshu
     *            多少条数据
     */
    public static void setTableModel(JScrollPane jScrollPane, List<Roleorder> salegoods) {

        /**
         * 设置监听
         */
        class MListener implements MouseListener {

            @Override
            public void mouseReleased(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mousePressed(MouseEvent e) {
                // TODO Auto-generated method stub

            }

            @Override
            public void mouseExited(MouseEvent e) {
                // TODO Auto-generated method stub
                JPanel source = (JPanel) e.getSource();
                source.setBackground(null);
                source.setOpaque(false);
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                // TODO Auto-generated method stub
                JPanel source = (JPanel) e.getSource();
                source.setBackground(UIUtils.COLOR_cbg5);
                source.setOpaque(true);
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
            }
        }

        /**
         * 表格
         */
        // JPanel jPanel = new JPanel();
        JPanel view = (JPanel) jScrollPane.getViewport().getView();
        view.removeAll();
        view.repaint();

        jScrollPane.getVerticalScrollBar().setUI(new TraslationDemoScrollBarUI(jScrollPane));
        jScrollPane.setViewportView(view);
        jScrollPane.setOpaque(false);
        jScrollPane.setBorder(null);
        jScrollPane.getViewport().setOpaque(false);
        Border js = BorderFactory.createEmptyBorder();
        jScrollPane.setBorder(js);
        jScrollPane.setVerticalScrollBarPolicy(20);
        jScrollPane.setHorizontalScrollBarPolicy(31);
        for (int i = 0; i < salegoods.size(); i++) {
            TraslationMyMainMygoodsModelJpanel traslationMyMainMygoodsModelJpanel = new TraslationMyMainMygoodsModelJpanel(
                    salegoods.get(i));
            traslationMyMainMygoodsModelJpanel.setBounds(0, i * 62, 740, 60);
            MListener mListener = new MListener();
            traslationMyMainMygoodsModelJpanel.addMouseListener(mListener);
            view.add(traslationMyMainMygoodsModelJpanel);
        }

        view.setPreferredSize(new Dimension(760, 62 * salegoods.size()));
        jScrollPane.updateUI();
        jScrollPane.invalidate();
        jScrollPane.validate();
        jScrollPane.repaint();
    }

}
